/*
 * @Author: hongbin
 * @Date: 2022-11-22 12:05:16
 * @LastEditors: hongbin
 * @LastEditTime: 2022-11-22 12:11:04
 * @Description:
 */
import { ObjectId } from "mongodb";
import { NextApiRequest, NextApiResponse } from "next";
import DB from "../mongodb";

export default async function handler(req: NextApiRequest, res: NextApiResponse<any>) {
    const db = await DB;
    const { id } = req.query;
    console.log("聊天记录ID:", id);
    const list = await db
        .collection("chatRecord")
        .find({ _id: new ObjectId(id as string) })
        .toArray();
    console.log("聊天记录", list[0]);
    if (!list.length) {
        return res.json({ code: -1, data: { msg: "没有找到对应数据，查找id:" + id } });
    }
    res.json(list[0]);
}
